package cn.lblbc.album.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import cn.lblbc.album.R
import cn.lblbc.album.model.ImageItem
import com.github.chrisbanes.photoview.PhotoView

class ImageViewerAdapter(private val images: List<ImageItem>) :
    RecyclerView.Adapter<ImageViewerAdapter.ImageViewerViewHolder>() {

    class ImageViewerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val photoView: PhotoView = itemView.findViewById(R.id.photoView)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageViewerViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_image_viewer, parent, false)
        return ImageViewerViewHolder(view)
    }

    override fun onBindViewHolder(holder: ImageViewerViewHolder, position: Int) {
        val image = images[position]
        
        // 使用PhotoView支持手势缩放
        holder.photoView.apply {
            setImageURI(android.net.Uri.parse("file://${image.path}"))
            setZoomable(true)
        }
    }

    override fun getItemCount(): Int = images.size
}